public class Solution1750 {
    public int minimumLength(String s) {
        int l=0,r=s.length()-1;
        char[] a=s.toCharArray();
        while (l<r){
            if (a[l]==a[r]){
                while (l<r && a[l]==a[l+1]){
                    l++;
                }
                l++;
                while (l<r && a[r]==a[r-1]){
                    r--;
                }
                r--;
            }else {
                return r-l+1;
            }
        }
        return l==r?1:0;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1750().minimumLength("bbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbccbcbcbccbbabbb"));
    }
}
